# coding: utf-8
# Game of Bombs - Projeto P1
# (C) 2014, Roberto Matheus, Angelo Costa / UFCG, Programação 1

# Jogo

import sys, pygame
from pygame.locals import *
from menu import *
from fases import *

class Jogo:
	
	done = False
	
	def __init__(self):
		pygame.init()
		self.size = (800, 600)
		self.screen = pygame.display.set_mode(self.size, 0, 32)
		pygame.mixer.music.load('sounds/Game-of-Thrones-8-b.mp3')
		pygame.mixer.music.play(-1) # Música infinita
		
		pygame.mouse.set_visible(0) # Desativa o mouse
		pygame.display.set_caption('Game of Bombs')
		
		self.menu = Menu(self.screen)
		self.loop()
	
	def loop(self):
		
		clock = pygame.time.Clock()
		
		while not self.done:
			clock.tick(30)
			
			self.screen.fill((0, 0, 0))
			
			self.menu.main_menu()
			
			self.trata_evento()
			
			pygame.display.update()
		
	def trata_evento(self):
		for event in pygame.event.get():
			t = event.type
			
			if t == KEYDOWN:
				k = event.key
				
			if t == QUIT:
				self.done = True
				
			if t == KEYDOWN:
				
				if k == K_ESCAPE:
					self.done = True
				
				if k == K_RETURN or k == K_KP_ENTER:
					
					if self.menu.botao_atual == 0:
						self.menu.menu_selecao_heroi()
						
					if self.menu.botao_atual == 1:
						self.menu.menu_creditos()
						
					if self.menu.botao_atual == 2:
						self.done = True
					
					if self.menu.botao_atual == 3:
						self.menu.menu_instrucoes()
						
				if k == K_UP or k == K_LEFT:
					self.menu.botao_atual -= 1
					
				if k == K_DOWN or k == K_RIGHT:
					self.menu.botao_atual += 1
				
				if k == K_F1:
					pygame.mixer.music.pause()
					
				if k == K_F2:
					pygame.mixer.music.unpause()
